#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <atomic>
#include <thread>
#include <pthread.h>

void* thread_handler(void* para)
{
    int data = *(int*)para;
    while (1) {
        sleep(2);
        printf("--- th data: [%d] ---\n", data);
    }
}

class Demo {
public:
    Demo() {
        printf("init Demo.\n");
    };

    void start() {
        printf("Demo start.\n");
        int num;
        num = 1;
        pthread_create(&m_th1, NULL, thread_handler, (void*)&num);
        sleep(1);
        num = 2;
        pthread_create(&m_th2, NULL, thread_handler, (void*)&num);
        sleep(1);
    }

    void stop() {
        printf("Demo stop.\n");
        pthread_cancel(m_th1);
        pthread_cancel(m_th2);
    }

    ~Demo() {
        printf("deinit Demo.\n");
    }

private:
    pthread_t m_th1;
    pthread_t m_th2;
};

int main(int argc, char* argv[])
{
    char buf[1024];
    printf("buf size: %d.\n", (int)sizeof(buf));
    return 0;
}